winsafe\dxgi\com_interfaces/idxgifactory.rs
1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::dxgi::{iterators::*, vts::*};
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9
10com_interface! { IDXGIFactory: "7b7166ec-21c7-44ae-b21a-c9ae321ae369";
11 /// [`IDXGIFactory`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nn-dxgi-idxgifactory)
12 /// COM interface.
13 ///
14 /// Automatically calls
15 /// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
16 /// when the object goes out of scope.
17 ///
18 /// Usually created with [`CreateDXGIFactory`](crate::CreateDXGIFactory)
19 /// function.
20 ///
21 /// # Examples
22 ///
23 /// ```no_run
24 /// use winsafe::{self as w, prelude::*};
25 ///
26 /// let factory = w::CreateDXGIFactory()?;
27 /// # w::HrResult::Ok(())
28 /// ```
29}
30
31impl dxgi_IDXGIObject for IDXGIFactory {}
32impl dxgi_IDXGIFactory for IDXGIFactory {}
33
34/// This trait is enabled with the `dxgi` feature, and provides methods for
35/// [`IDXGIFactory`](crate::IDXGIFactory).
36///
37/// Prefer importing this trait through the prelude:
38///
39/// ```no_run
40/// use winsafe::prelude::*;
41/// ```
42pub trait dxgi_IDXGIFactory: dxgi_IDXGIObject {
43 /// [`IDXGIFactory::CreateSoftwareAdapter`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-createsoftwareadapter)
44 /// method.
45 #[must_use]
46 fn CreateSoftwareAdapter(&self, hmodule: &HINSTANCE) -> HrResult<IDXGIAdapter> {
47 let mut queried = unsafe { IDXGIAdapter::null() };
48 ok_to_hrresult(unsafe {
49 (vt::<IDXGIFactoryVT>(self).CreateSoftwareAdapter)(
50 self.ptr(),
51 hmodule.ptr(),
52 queried.as_mut(),
53 )
54 })
55 .map(|_| queried)
56 }
57
58 /// [`IDXGIFactory::CreateSwapChain`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-createswapchain)
59 /// method.
60 #[must_use]
61 fn CreateSwapChain(
62 &self,
63 device: &impl ole_IUnknown,
64 desc: &DXGI_SWAP_CHAIN_DESC,
65 ) -> HrResult<IDXGISwapChain> {
66 let mut queried = unsafe { IDXGISwapChain::null() };
67 ok_to_hrresult(unsafe {
68 (vt::<IDXGIFactoryVT>(self).CreateSwapChain)(
69 self.ptr(),
70 device.ptr(),
71 pcvoid(desc),
72 queried.as_mut(),
73 )
74 })
75 .map(|_| queried)
76 }
77
78 /// [`IDXGIFactory::EnumAdapters`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-enumadapters)
79 /// method.
80 ///
81 /// Returns an iterator over [`IDXGIAdapter`](crate::IDXGIAdapter) elements.
82 ///
83 /// # Examples
84 ///
85 /// ```no_run
86 /// use winsafe::{self as w, prelude::*};
87 ///
88 /// let factory: w::IDXGIFactory; // initialized somewhere
89 /// # let factory = unsafe { w::IDXGIFactory::null() };
90 ///
91 /// for adapter in factory.EnumAdapters() {
92 /// let adapter = adapter?;
93 /// // ...
94 /// }
95 ///
96 /// // Collecting into a Vec
97 /// let adapters: Vec<w::IDXGIAdapter> =
98 /// factory.EnumAdapters()
99 /// .collect::<w::HrResult<_>>()?;
100 /// # w::HrResult::Ok(())
101 /// ```
102 #[must_use]
103 fn EnumAdapters(&self) -> impl Iterator<Item = HrResult<IDXGIAdapter>> + '_ {
104 IdxgifactoryEnumadaptersIter::new(self)
105 }
106
107 /// [`IDXGIFactory::GetWindowAssociation`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-getwindowassociation)
108 /// method.
109 #[must_use]
110 fn GetWindowAssociation(&self) -> HrResult<HWND> {
111 let mut hwnd = HWND::NULL;
112 ok_to_hrresult(unsafe {
113 (vt::<IDXGIFactoryVT>(self).GetWindowAssociation)(self.ptr(), hwnd.as_mut())
114 })
115 .map(|_| hwnd)
116 }
117
118 /// [`IDXGIFactory::MakeWindowAssociation`](https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgifactory-makewindowassociation)
119 /// method.
120 fn MakeWindowAssociation(&self, hwnd: &HWND, flags: co::DXGI_MWA) -> HrResult<()> {
121 ok_to_hrresult(unsafe {
122 (vt::<IDXGIFactoryVT>(self).MakeWindowAssociation)(self.ptr(), hwnd.ptr(), flags.raw())
123 })
124 }
125}